package com.toman.Adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.toman.Entity.DeletaAccout_Entity;
import com.toman.MyApplication;
import com.toman.R;

import java.util.ArrayList;

/**
 * Created by  GridView_adpter on Administrator on 2017/11/3 on 16:13.
 */

public class DeleteAccout_adpter extends BaseAdapter {

    //上下文对象
    Context context;
    //  arrayList
    ArrayList<DeletaAccout_Entity> arrayList;

    LayoutInflater inflater;

    MyApplication myApplication;

    LinearLayout mAd_bg;
    ImageView mdel_img;
    int Anint;


    public DeleteAccout_adpter(Context context, ArrayList<DeletaAccout_Entity> arrayList, MyApplication myApplication, int Anint) {
        this.context = context;
        this.arrayList = arrayList;
        this.myApplication = myApplication;
        this.Anint = Anint;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AddPackage addPackage;
        if (null == convertView) {
            addPackage = new AddPackage();
            convertView = inflater.inflate(R.layout.del_item, null, false);
            addPackage.img = (ImageView) convertView.findViewById(R.id.mDelImg);
            addPackage.title = (TextView) convertView.findViewById(R.id.mTitle);
            mAd_bg = (LinearLayout) convertView.findViewById(R.id.mAd_bg);
            mdel_img = (ImageView) convertView.findViewById(R.id.mdel_img);

            convertView.setTag(addPackage);
        } else {
            addPackage = (AddPackage) convertView.getTag();
        }

        if (myApplication.getSp().getString("token", "").equals("toman")) {
            mAd_bg.setBackgroundResource(R.color.loginbg);

        } else if (myApplication.getSp().getString("token", "").equals("operater")) {
            mAd_bg.setBackgroundResource(R.color.g7bg);

        } else if (myApplication.getSp().getString("token", "").equals("company")) {
            if (Anint == 1) {
                mdel_img.setVisibility(View.VISIBLE);
            } else {
                mdel_img.setVisibility(View.GONE);
            }
            mAd_bg.setBackgroundResource(R.color.c1);

        }
        if (Anint == 1) {
            addPackage.img.setBackgroundResource(arrayList.get(position).getImg());
        } else {
            addPackage.img.setBackgroundResource(R.mipmap.chanxian);
        }
        addPackage.title.setText(arrayList.get(position).getTitle());

        return convertView;
    }


    public class AddPackage {
        ImageView img;
        TextView title;
    }

}
